Repository navigation
Conversation
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
|
Droid encountered an error —— View job |
a5657ca to
37d62d7
Compare
[Medium impact] The setting reaches media requests across downloading, playback, and slide workflows. The PR appears safe to merge, with a non-blocking gap in keeping refused chunk paths out of logs. Findings
SummaryAdds opt-in
Acknowledged limitation: rabesss states that generic
|
| if strictErr := strictOriginRefusal(err); strictErr != nil { | ||
| // Nothing was sent. Report only the refused origin, never the | ||
| // chunk URL, whose path or query may carry signing material. | ||
| return "", nil, 0, fmt.Errorf("chunk %d request refused: %w", chunk, strictErr) |
There was a problem hiding this comment.
Refused paths still reach logs
This branch misses strict refusals that return MediaOriginError. For example, with bearer test-token, strict mode refuses https://test-token.cdn.example/private-signed-path/segment.ts, but strictOriginRefusal(err) returns nil because the client deliberately omitted the typed origin error. The fallback then includes the URL in the chunk error. RedactURLWithToken removes the bearer but keeps the private path, so signed paths can still reach errors and logs. Drop the chunk URL for generic policy errors in strict mode too.
How this was verified: The bearer-bearing host selects the generic refusal, which misses the typed check and reaches a URL formatter that preserves the path.
|
Droid encountered an error —— View job |
There was a problem hiding this comment.
ℹ️ No critical issues — one small test-helper gap inline.
Reviewed changes
- Strict pre-send refusal in the client: new
GetAuthorizedWithMediaPolicywithMediaRequestPolicy{Origins, Strict}refuses an unlisted origin before anything is sent — both on the initial request and on each redirect hop, checked before and after a caller-suppliedCheckRedirecthook.GetAuthorizedWithTokenForOriginsbecomes a thin non-strict wrapper, so default behavior is unchanged. - Typed refusal reuses existing plumbing: the refusal is
*UnconfiguredMediaOriginError{Strict: true}carrying onlyscheme://host[:port]; via the newIsmethod it also matchesErrMediaOrigin, and it flows through the download summary, pipeline failures, playback failures channel, andsanitizeUpstreamErrwithout new code.retry.Retryable's allowlist correctly never retries it. - Unforgeable redirect carrier: strict redirect refusals leave
http.Client.Doinside the unexportedstrictRedirectRefusaltype, so a hook cannot forge a trusted refusal; hook errors still take the sanitizing branch. Origins containing any representation of the bearer fall back to the genericErrMediaOriginrather than echoing it. - Wiring:
strictMediaOriginsconfig (JSON +IMPARTUS_STRICT_MEDIA_ORIGINS, defaultfalse, invalid env rejected), downloadermediaPolicy()for chunks/keys/playback segments,GetPlaylists, and server slide redirects; chunk errors drop the refused URL so signed paths/queries never reach logs. - Tests: ~450 lines across client, downloader (serial + pipeline + playback), server, and config — all pinning 0 network requests and no leakage of the refused URL or bearer.
go vet ./...andgo test -race -count=1are green on all four touched packages in this environment.
glm-5.3 | 𝕏
| applyStringEnv("IMPARTUS_RETRY_BUDGET", &cfg.RetryBudget) | ||
| applyStringEnv("IMPARTUS_LISTEN_ADDR", &cfg.ListenAddr) | ||
| for _, apply := range []func() error{ | ||
| func() error { return applyBoolEnv("IMPARTUS_STRICT_MEDIA_ORIGINS", &cfg.StrictMediaOrigins) }, |
There was a problem hiding this comment.
IMPARTUS_STRICT_MEDIA_ORIGINS is missing from the unsetAllConfigEnv list in internal/config/config_test.go (around line 719), which deliberately enumerates every config env var to give tests a clean slate. No test today asserts strict-related state after that helper, so nothing can fail — but the list's contract is "all config env", and the new var belongs there.
There was a problem hiding this comment.
ℹ️ The new commit is a pure amend of the reviewed head — nothing new to cover.
Reviewed changes
- Re-checked the delta from
a5657cato37d62d7: the PR's net diff is byte-identical, so this commit introduces no new code, docs, or test changes. The prior review covers the current head in full; its single inline suggestion (addIMPARTUS_STRICT_MEDIA_ORIGINStounsetAllConfigEnvininternal/config/config_test.go) still stands.
glm-5.3 | 𝕏
… bearer Council round 1 on #308: catch a mixed-case bearer in a refused hostname, keep the strict refusal typed with the origin withheld so playback reports it and chunk errors stay URL-free, drop the chunk URL on any strict-mode policy refusal, stop reporting ErrMediaOrigin as an authentication failure in job errors, fix two errcheck type assertions, and correct the README on default redirect handling.
|
Droid encountered an error —— View job |
There was a problem hiding this comment.
ℹ️ No new issues in this delta — approval is withheld only because the earlier
unsetAllConfigEnvsuggestion (internal/config/config_test.go) is still open; that thread is pre-existing, not a new blocker.
Reviewed changes
The delta 37d62d7..ce29a5f reworks how a strict refusal behaves when the refused origin itself carries the bearer, and tightens what strict-mode chunk errors and server job errors reveal.
- Kept bearer-carrying strict refusals typed:
strictOriginRefusalnow returns*UnconfiguredMediaOriginError{Strict: true}withOriginempty instead of falling back to the genericErrMediaOrigin, so playback, pipeline and download-summary surfaces all report it; detection covers a mixed-case bearer in both the raw and the folded host. - Added a withheld-origin message:
Error()explains the origin was withheld because it contains the login token, keeping the refusal actionable without echoing it. - Dropped the chunk URL for every strict-mode policy refusal: chunk errors now omit the URL for any
ErrMediaOriginmatch when strict mode is on (e.g. a same-origin redirect whoseLocationcarries the bearer), not only for typed strict refusals. - Stopped reporting policy refusals as login failures on the server:
sanitizeUpstreamErrmaps any otherErrMediaOriginrefusal to a fixed "media request refused by the media origin policy" message instead of "upstream authentication failed". - Extended tests and docs: mixed-case bearer in request and redirect hosts, withheld-origin chunk and playback reporting, the other-policy-refusal URL drop (pinning 0 redirect hits), and server sanitization; the README now states default mode already refuses redirects to unlisted origins.
go vetandgo test -race -count=1are green on all four touched packages in this environment.
glm-5.3 | 𝕏
|
Droid encountered an error —— View job |
…media origins strictMediaOrigins (IMPARTUS_STRICT_MEDIA_ORIGINS) refuses playlist, segment, key, slide and redirect requests to any origin outside baseUrl and mediaOrigins before they are sent. The refusal is an UnconfiguredMediaOriginError with Strict set: it names only the refused scheme://host[:port], matches ErrMediaOrigin and ErrUnconfiguredMediaOrigin, and is never reported as a login failure. Off by default so lectures whose playlists name an unlisted CDN keep downloading; those origins are still contacted without the bearer. Closes #248
… bearer Council round 1 on #308: catch a mixed-case bearer in a refused hostname, keep the strict refusal typed with the origin withheld so playback reports it and chunk errors stay URL-free, drop the chunk URL on any strict-mode policy refusal, stop reporting ErrMediaOrigin as an authentication failure in job errors, fix two errcheck type assertions, and correct the README on default redirect handling.
Assert the unused chunk results instead of discarding three values, describe a withheld origin as looking like a credential, name the media URL policy in server job errors, and document the withheld-origin case in the README.
33707ce to
08be14b
Compare
|
Droid encountered an error —— View job |
There was a problem hiding this comment.
ℹ️ No new issues in this delta. Approval remains withheld only because the pre-existing
unsetAllConfigEnvsuggestion (internal/config/config_test.go) is still open — nothing in this delta blocks.
Reviewed changes
The delta ce29a5f..08be14b (the prior head amended to d6c90f3 with identical content, plus one new commit) is wording, documentation, and test hardening only — no control flow changed.
- Clarified the withheld-origin refusal message:
UnconfiguredMediaOriginError.Error()now says the origin was withheld because it "looks like a credential" rather than asserting it contains the login token, which matches what the detection actually establishes. Type, classification, and the loose"withheld"test assertion are unchanged. - Clarified the server's policy-refusal job error:
mediaOriginPolicyRefusalnow reads "media URL rejected by the media URL policy (check mediaOrigins / IMPARTUS_MEDIA_ORIGINS and that the URL is HTTPS without credentials)" — more accurate for a branch that also catches invalid-URLErrMediaOriginmatches, and now tells the user what to check. - Hardened the refused-chunk tests: the two withheld-origin chunk tests now assert the refusal returns an empty path, nil data, and zero bytes written (also satisfying the
dogsledlinter). - Documented withheld origins in the README: the strict-media-origins section now explains that a refused origin which looks like it contains the login token is left out of the error.
go vet ./... and go test -race -count=1 are green on all four touched packages in this environment.
glm-5.3 | 𝕏

Description
What does this PR do?
Adds an opt-in
strictMediaOriginsconfig option (IMPARTUS_STRICT_MEDIA_ORIGINS). When it is on, playlist, segment, decryption-key, slide and redirect requests to any origin other thanbaseUrlandmediaOriginsare refused before anything is sent: no DNS lookup, no connection, no request. Without the option, behaviour is unchanged: an unlisted origin is still contacted, with the bearer withheld.The refusal is the existing
*client.UnconfiguredMediaOriginError, with a newStrictfield set. That means every surface that already explains "not in mediaOrigins" instead of "wrong credentials" handles it with no new plumbing (download summary, pipeline, playback failures channel, serversanitizeUpstreamErr):ErrUnconfiguredMediaOrigin(throughUnwrap, which keeps its single-error contract) andErrMediaOrigin(through a newIsmethod). It never matchesErrAuthentication, andretry.Retryablenever retries it.scheme://host[:port]. If that origin contains any representation of the bearer (or credential-shaped text), in any letter case, the refusal keeps its type and classification but leavesOriginempty and says the origin was withheld. Chunk errors drop the chunk URL for strict refusals and for any other strict-modeErrMediaOriginrefusal, so a signed path or query never reaches logs.CheckRedirecthook runs, so a hook that rewrites an allowed hop to an unlisted origin is refused too. Only refusals built internally are passed through unsanitized: they travel inside an unexported carrier, so a hook cannot forge a "trusted"UnconfiguredMediaOriginErrorwith arbitrary fields.GetAuthorizedWithMediaPolicy(ctx, url, token, client.MediaRequestPolicy{Origins, Strict}).GetAuthorizedWithTokenForOriginsis now a thin wrapper around it (non-strict).Why opt-in (default
false)Refusing by default would break real users today. The README ships
"mediaOrigins": [], and HLS playlists from the upstream can name segment and key URLs on a CDN origin the user has never listed. With strict mode on by default, those lectures would stop downloading on upgrade, with no change on the user's side. Off by default, they keep working exactly as before, and the bearer is still withheld from those origins (#245/#297). Users who want "never contact anything I didn't list" can turn it on and get an actionable error naming the origin to add. Issue #248 proposes it as an option, and flipping the default later is a one-line change once users have had a release to populatemediaOrigins. This is documented in the README config table, the env table and a new "Strict media origins" section.Related Issue(s):
;re-encoding) had no open PR when this was written.Type of Change
Testing Done
Unit Tests:
go vet ./...,go test -race -count=1 ./...,golangci-lintv2.12.1 → 0 issues; run on a clean instabox because the workstation is overloaded)New tests (all use local
httptestservers or a routing transport with hit counters; nothing contacts the real LMS):internal/client/media_origin_strict_test.go: the issue's five variants refused with 0 requests; configured origins still get the bearer; non-strict mode still contacts unlisted origins without the bearer; redirect to an unlisted origin (with and without a token); a caller hook rewriting an allowed redirect; an allowed redirect is followed; a bearer inside the host, including mixed case on the first request and on a redirectLocation, is never echoed and the refusal stays typed with the origin withheld;GetPlaylistsrefuses an unlisted playlist origin; a forged hook error is not trusted;Error/Is/Unwrapcontract.internal/downloader/strict_media_origin_test.go: chunk, decryption key,DownloadPlaylist(serial and pipeline), playback key startup and playback segment failure reporting. Each checks 0 requests, the typed refusal, and that the refused URL's path or query never appears in the error. Also: a bearer-carrying chunk and playback-segment origin is refused typed with the origin withheld, and a same-origin redirect whoseLocationcarries the bearer drops the chunk URL.internal/server: a strict slide redirect is refused with the named origin;sanitizeUpstreamErrexplains a strict refusal without the URL or "authentication failed".internal/config: default false, JSON key, env override in both directions, invalid env rejected,ApplyDefaultspreserves the value.Mutation checks: disabling the strict check in
client.go/http.go, the URL-dropping branch indownload_chunks.go, or the type-preserving branch inplay.goeach makes the matching new tests fail.Code Quality Checklist
Documentation
sample.config.jsongains"strictMediaOrigins": falseAdditional Context
The plan was reviewed before implementation (Terra xhigh). Its findings were fixed: hook-forged typed errors, chunk-URL leakage, the
Unwrapcontract, playback key type preservation, and the extra boundary tests.Council round 1 (head 37d62d7) fixes: errcheck lint on two test type assertions; a mixed-case bearer in a hostname is now caught (Opus P2); a bearer-carrying origin keeps the typed strict refusal with the origin withheld, so playback reports it and chunk errors stay URL-free (Terra P1/P2); chunk errors also drop the URL for any other strict-mode policy refusal; README now says default mode already refuses redirects to unlisted origins (Opus P3); server job errors no longer report a generic
ErrMediaOriginpolicy refusal as "upstream authentication failed" (Muse P2).Council round 2 (head ce29a5f): Opus and Muse Spark approved with no P0/P1. Terra's run stopped before giving a verdict, so it is rerun in round 3. Fixes in round 3's head: CI dogsled lint in two downloader tests; clearer wording for a withheld origin and for the server's policy message (Opus P3); the README now documents the withheld-origin case (Muse P3). The branch was rebased on main (55a95db) with no change to this PR's diff (
git range-diffshows identical commits), and it merges cleanly with the open #311.Deferred P3 findings are tracked in #317. The Factory
droid-reviewcheck fails on Factory's own usage quota. It is not a required check, and it is not related to this change.Council round 3 (head 08be14b, rebased on main 55a95db): Opus high and Muse Spark xhigh approved with no findings. Terra xhigh reported one P1 and one P2. The P1 (a hostname containing a hex-encoded token is named in the strict refusal) is triaged to P2 hardening and does not block this PR. Main's default-mode refusal already names the origin with no token check at all. No redaction path in
internal/secretsknows hex or base64 token forms. Default mode also contacts that host, which strict mode never does, so this PR narrows the exposure rather than widening it. Both Terra items are tracked in #317, with the fix belonging ininternal/secrets.Not merged yet: #311 merged to main (4a9bb6f) after round 3 and touches six of this PR's files. A trial merge with 4a9bb6f is conflict-free, and
go vetplusgo testpass for client, downloader, server, config and watch. This PR's rule is to rebase after #311 and rerun all three seats on the rebased head before merging, so the PR is waiting for that one rebase-and-review round.